Skip to content

test(agent-memory): isolate integration tests with unique agent ID and teardown cleanup - #277

Open
cassiofariasmachado wants to merge 2 commits into
mainfrom
test/improve-agent-memory-integration-tests
Open

test(agent-memory): isolate integration tests with unique agent ID and teardown cleanup#277
cassiofariasmachado wants to merge 2 commits into
mainfrom
test/improve-agent-memory-integration-tests

Conversation

@cassiofariasmachado

Copy link
Copy Markdown
Member

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

Integration tests for the Agent Memory module were accumulating records in the shared backend on every run because all tests used the hardcoded agent_id "test-agent". Over time this caused the vector index to grow (observed at 37,873 records), making the semantic search endpoint time out.

This PR fixes the issue by:

  • Introducing a run_agent_id session-scoped fixture that generates a unique test-agent-<8hex> ID per run, so each run's data is fully isolated.
  • Adding a _delete_all_memories helper that paginates through all records for the run's agent_id and deletes them in teardown, keeping the backend clean after every run.
  • Updating all step functions that previously hardcoded or forwarded "test-agent"/"test-user" to read from context["agent_id"] and context["invoker_id"] instead.
  • Fixing the check_memory_agent_id and check_memory_invoker_id assertion steps to compare against the runtime values rather than the literal strings from the feature file.

Related Issue

N/A

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Code refactoring

How to Test

  1. Run the integration tests: uv run pytest tests/agent_memory/integration -v
  2. All 14 provider tests should pass, including test_search_memories
  3. Run them a second time — test_search_memories should remain fast because the previous run's data was cleaned up

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Breaking Changes

None.

Additional Notes

The feature file (agentmemory.feature) is unchanged — it still references "test-agent" and "test-user" as readable scenario labels. The step implementations now ignore those parsed values in favour of the runtime-isolated IDs from context.

@cassiofariasmachado
cassiofariasmachado requested a review from a team as a code owner August 19, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant